package demo.genericity;

import java.util.ArrayList;
import java.util.Random;

/**
 * 随即列表
 *
 * @author sun.ye
 * @since 2020-07-05 19:40
 */
public class RandomList<T> {

    private ArrayList<T> storage = new ArrayList<>();
    private Random random = new Random(47);
    public void add(T item){
        storage.add(item);
    }
    public T select(){
        return storage.get(random.nextInt(storage.size()));
    }

    public static void main(String[] args) {
        RandomList<String> randomList = new RandomList<>();
        for (String str :"This is a random list and I have nothing to say !".split(" ") ) {
            randomList.add(str);
        }
        for (int i = 0 ; i < 11 ; i++) {
            System.out.println(randomList.select());
        }
    }
}